Make GtkCellAreaBox handle rendering without a previous allocation in the orientation...
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Thu, 25 Nov 2010 07:09:51 +0000 (16:09 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Thu, 25 Nov 2010 07:09:51 +0000 (16:09 +0900)
This is so that treeviews can have some columns oriented vertically and
some horizontally, usually the column will only allocate the areas
width, having vertical columns without fixed row heights just means
it's slower to render.

gtk/gtkcellareabox.c
gtk/gtkcellareaboxcontext.c
gtk/gtkcellareaboxcontext.h

index a269cf5d9ae0e09f65139e41b7ca02908ca2320f..5bfcf1e00a5bd57826b8c0353aeb80a483dfd63e 100644 (file)
@@ -166,7 +166,8 @@ static void           init_context_group     (GtkCellAreaBox        *box,
                                              GtkCellAreaBoxContext *context);
 static GSList        *get_allocated_cells    (GtkCellAreaBox        *box,
                                              GtkCellAreaBoxContext *context,
-                                             GtkWidget             *widget);
+                                             GtkWidget             *widget,
+                                             gint                   orientation_size);
 
 
 struct _GtkCellAreaBoxPrivate
@@ -570,22 +571,22 @@ flush_contexts (GtkCellAreaBox *box)
 static GSList *
 get_allocated_cells (GtkCellAreaBox        *box,
                     GtkCellAreaBoxContext *context,
-                    GtkWidget             *widget)
+                    GtkWidget             *widget,
+                    gint                   orientation_size)
 {
-  const GtkCellAreaBoxAllocation *group_allocs;
-  GtkCellArea                    *area = GTK_CELL_AREA (box);
-  GtkCellAreaBoxPrivate          *priv = box->priv;
-  GList                          *cell_list;
-  GSList                         *allocated_cells = NULL;
-  gint                            i, j, n_allocs;
+  GtkCellAreaBoxAllocation *group_allocs;
+  GtkCellArea              *area = GTK_CELL_AREA (box);
+  GtkCellAreaBoxPrivate    *priv = box->priv;
+  GList                    *cell_list;
+  GSList                   *allocated_cells = NULL;
+  gint                      i, j, n_allocs;
+  gboolean                  free_allocs = FALSE;
 
   group_allocs = gtk_cell_area_box_context_get_orientation_allocs (context, &n_allocs);
   if (!group_allocs)
     {
-      g_warning ("Trying to operate on an unallocated GtkCellAreaContext, "
-                "GtkCellAreaBox requires that the context be allocated at least "
-                "in the orientation of the box");
-      return NULL;
+      group_allocs = gtk_cell_area_box_context_allocate (context, orientation_size, &n_allocs);
+      free_allocs  = TRUE;
     }
 
   for (i = 0; i < n_allocs; i++)
@@ -685,6 +686,9 @@ get_allocated_cells (GtkCellAreaBox        *box,
        }
     }
 
+  if (free_allocs)
+    g_free (group_allocs);
+
   /* Note it might not be important to reverse the list here at all,
    * we have the correct positions, no need to allocate from left to right */
   return g_slist_reverse (allocated_cells);
@@ -838,7 +842,9 @@ gtk_cell_area_box_get_cell_allocation (GtkCellArea          *area,
 
   /* Get a list of cells with allocation sizes decided regardless
    * of alignments and pack order etc. */
-  allocated_cells = get_allocated_cells (box, box_context, widget);
+  allocated_cells = get_allocated_cells (box, box_context, widget, 
+                                        priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
+                                        cell_area->width : cell_area->height);
 
   for (l = allocated_cells; l; l = l->next)
     {
@@ -914,7 +920,9 @@ gtk_cell_area_box_event (GtkCellArea          *area,
 
          /* Get a list of cells with allocation sizes decided regardless
           * of alignments and pack order etc. */
-         allocated_cells = get_allocated_cells (box, box_context, widget);
+         allocated_cells = get_allocated_cells (box, box_context, widget, 
+                                                priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
+                                                cell_area->width : cell_area->height);
 
          for (l = allocated_cells; l; l = l->next)
            {
@@ -1016,7 +1024,9 @@ gtk_cell_area_box_render (GtkCellArea          *area,
 
   /* Get a list of cells with allocation sizes decided regardless
    * of alignments and pack order etc. */
-  allocated_cells = get_allocated_cells (box, box_context, widget);
+  allocated_cells = get_allocated_cells (box, box_context, widget, 
+                                        priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
+                                        cell_area->width : cell_area->height);
 
   for (l = allocated_cells; l; l = l->next)
     {
index e0501e6944fc1d2a1d44ae8d2dbe2ce4f9463a5b..caf23df0712dacf382ef99844a4c71b389ddc604 100644 (file)
@@ -562,8 +562,8 @@ gtk_cell_area_box_context_allocate_width (GtkCellAreaContext *context,
 {
   GtkCellAreaBoxContext        *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
   GtkCellAreaBoxContextPrivate *priv        = box_context->priv;
-  GtkCellArea               *area;
-  GtkOrientation             orientation;
+  GtkCellArea                  *area;
+  GtkOrientation                orientation;
 
   area        = gtk_cell_area_context_get_area (context);
   orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
@@ -604,6 +604,7 @@ gtk_cell_area_box_context_allocate_height (GtkCellAreaContext *context,
   GTK_CELL_AREA_CONTEXT_CLASS (gtk_cell_area_box_context_parent_class)->allocate_height (context, height);
 }
 
+
 /*************************************************************
  *                            API                            *
  *************************************************************/
@@ -870,7 +871,7 @@ gtk_cell_area_box_context_get_heights (GtkCellAreaBoxContext *box_context,
   return gtk_cell_area_box_context_get_requests (box_context, GTK_ORIENTATION_VERTICAL, n_heights);
 }
 
-G_CONST_RETURN GtkCellAreaBoxAllocation *
+GtkCellAreaBoxAllocation *
 gtk_cell_area_box_context_get_orientation_allocs (GtkCellAreaBoxContext *context,
                                                  gint                  *n_allocs)
 {
@@ -883,4 +884,21 @@ gtk_cell_area_box_context_get_orientation_allocs (GtkCellAreaBoxContext *context
   *n_allocs = priv->n_orientation_allocs;
 
   return priv->orientation_allocs;
+
+}
+
+GtkCellAreaBoxAllocation *
+gtk_cell_area_box_context_allocate (GtkCellAreaBoxContext *context,
+                                   gint                   orientation_size,
+                                   gint                  *n_allocs)
+{
+  GtkCellArea    *area;
+  GtkOrientation  orientation;
+  gint            spacing;
+
+  area        = gtk_cell_area_context_get_area (GTK_CELL_AREA_CONTEXT (context));
+  orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
+  spacing     = gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (area));
+
+  return allocate_for_orientation (context, orientation, spacing, orientation_size, n_allocs);
 }
index 4f9c02d9b16bcda22a42338ab81a5874aad07db2..01f7dc6cba6d15bc1dc40ae9d3380572d9e84f04 100644 (file)
@@ -125,10 +125,15 @@ typedef struct {
   gint size;      /* Full allocated size of the cells in this group spacing inclusive */
 } GtkCellAreaBoxAllocation;
 
-G_CONST_RETURN GtkCellAreaBoxAllocation *
+GtkCellAreaBoxAllocation *
 gtk_cell_area_box_context_get_orientation_allocs (GtkCellAreaBoxContext *context,
                                                  gint                  *n_allocs);
 
+GtkCellAreaBoxAllocation *
+gtk_cell_area_box_context_allocate (GtkCellAreaBoxContext *context,
+                                   gint                   orientation_size,
+                                   gint                  *n_allocs);
+
 G_END_DECLS
 
 #endif /* __GTK_CELL_AREA_BOX_CONTEXT_H__ */